<template>
  <div class="icons">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(page,index) in pages" :key="index">
        <div class="icon" v-for="item in iconList" :key="item.id">
          <img :src="item.imgUrl"/>
          <p>{{item.desc}}</p>
        </div>
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>

  </div>

</template>

<script>
  import Swiper from "../../../node_modules/vue-awesome-swiper/src/swiper";
  import SwiperSlide from "../../../node_modules/vue-awesome-swiper/src/slide";
  export default {
    components: {SwiperSlide, Swiper}, name: "HomeIcons",
    props:{
      iconList:Array
    },
    data(){
      return{
        swiperOption:{
          pagination: '.swiper-pagination'
        }
      }
    },
    computed:{
      pages(){
        const pages= []
        //对每一项数据进行循环
        this.iconList.forEach((item, index) => {
          const page=Math.floor(index / 8)
          if(!pages[page]){
            pages[page]=[]
          }
          pages[page].push(item)
        })
        return pages
      }
    }
  }
</script>

<style lang="stylus" scoped>
  .icons >>> .swiper-wrapper{
    height 0;
    padding-bottom 50%;
  }
  .icons >>> .swiper-container-horizontal > .swiper-pagination-bullets{
    bottom -2px;
  }
  .icons{
    /*border 1px solid red;*/
    .icon{
      width 25%;
      height 0;
      padding-bottom 25%;
      overflow hidden;
      text-align center;
      float left;
      img{
        width 65%;
        margin-top .1rem;
      }
    }
  }
</style>
